<template src="./template.html"></template>

<style src="./style.css" scoped></style>

<script>
    import api from "api/api";
    import modal from "utils/modal";
    const moneyType = 2; //冻结余额明细

    export default{
        data() {
            return {
                freezeList: [],
                start: 0,
                limit: 9,
                refEl: 'cell_0',//n起始值为0
                showGoTop: false,//默认置顶按钮为隐藏
                loading: false, //正在加载
                listLoaded: false, //默认的页面没有加载
                listCompleted: false //分页完成
            }
        },
        created() {
            let self = this;
            let _params = {
                start: self.start,
                limit: self.limit,
                type: moneyType
            };

            self.sendHttp(_params,res=>{
                self.listLoaded = true;
                self.freezeList = res.data.frozenFinance || [];

                 //总数据量小于limit
                 if(self.freezeList.length < self.limit) {
                    self.listCompleted=true;
                 }
            });
        },
        methods: {
            sendHttp(params,succCallback,failCallback){
                api.sendHttp("getMyMoneyApi",params).then(res=>{
                    if(typeof succCallback == "function") succCallback(res);
                },
                res=>{
                    modal.toast(res.msg);
                    if(typeof failCallback == "function") failCallback(res);
                });
            },
            fetchMore(){
                this.$refs['list'].resetLoadmore(); //下一次滚动时强制触发loadmore

                let self = this;
                if(self.listCompleted || self.loading) {
                    return false;
                }

                self.loading = true;
                let temp = self.start + self.limit;
                self.start = temp;

                let _params = {
                    start: self.start,
                    limit: self.limit,
                    type: moneyType
                };

                self.sendHttp(_params,res=>{
                    self.loading = false;
                    let data = res.data || {};
                    let _freezeList = data.frozenFinance || [];

                    if(_freezeList.length < self.limit) self.listCompleted = true;
                    self.freezeList = self.freezeList.concat(_freezeList);
                });
            },
            onScroll(e) {
                let contentOffset = e.contentOffset;
                let offsetY = contentOffset.y;
                if(offsetY <= -2000){
                    if(!this.showGoTop) this.showGoTop = true;
                } else if(offsetY > -2000) {
                    if(this.showGoTop) this.showGoTop = false;
                }
            }
        }
    }
</script>
